﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LD.Controls.TextBox
{
    [ToolboxItem(true)]
    public partial class TimeEditTextControl : UserControl
    {
        public string text = string.Empty;
        public TimeEditTextControl():base()
        {
            InitializeComponent();
            textBox1.Visible = true;//文本可见
            dateTimePicker1.Visible = false;//日期不可见
            dateTimePicker1.CloseUp += DateTimePicker1_CloseUp;
        }

    
        /// <summary>
        /// 选择日期按钮点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void textBox1_Click(object sender, EventArgs e)
        {
            dateTimePicker1.Visible = true;//显示日期控件
            dateTimePicker1.Focus();//焦点停留
            SendKeys.Send("{F4}");


        }

        /// <summary>
        /// 选择完成后触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DateTimePicker1_CloseUp(object sender, EventArgs e)
        {
            textBox1.Text = dateTimePicker1.Value.ToShortDateString();
            dateTimePicker1.Visible = false;
            text = textBox1?.Text;
        }
    }
}
